﻿using Basic.FormCollect;
using Basic.FormLocalEvent.Model;
using Basic.FormModel.DB;
using Basic.FormRemoteModel;
using WeDonekRpc.Client.Attr;
using WeDonekRpc.Client.Interface;

namespace Basic.FormLocalEvent.Form
{
    [LocalEventName("Delete")]
    internal class ClearFormView : IEventHandler<FormEvent>
    {
        private readonly IFormViewCollect _Service;

        public ClearFormView ( IFormViewCollect service )
        {
            this._Service = service;
        }

        public void HandleEvent ( FormEvent data, string eventName )
        {
            if ( data.Form.FormType == FormType.视图 )
            {
                DBFormView sour = this._Service.Find(data.Form.Id);
                if ( sour != null )
                {
                    this._Service.Delete(sour, data.Form.TableName);
                }
            }
        }
    }
}
